package com.codeforces.gym.g100184;

import java.util.Scanner;

public class E {

	static Scanner scanner = new Scanner(System.in);
	static int N, M;
	static long sum;
	static long[] A = new long[100001];
	static long[] f = new long[100001];

	public static void main(String[] args) {
		N = scanner.nextInt();
		M = scanner.nextInt();
		for (int i=1;i<=N;++i) {
			A[i] = scanner.nextInt();
		}
		sum = 0;
		for (int i=1;i<=M;++i) {
			f[i] = 0;
			if (i + M <= N) {
				f[i+M] = Math.max(A[i+M] + A[i], 0);
				int mul = 1;
				mul++;
				while (i + M * mul <= N) {
					f[i + M * mul] = 
							Math.max(f[i + M * (mul - 1)], A[i + M * mul] + A[i + M * (mul - 1)] + f[i + M * (mul - 2)]);
					mul++;
				}
				long last = f[i + M * (mul - 1)];
				sum += last;
			}
		}
		System.out.println(sum);
	}

}
